import { useEffect, useRef } from 'react';

/**
 *
 * @param {function} fn 返回为 true 时, 不再执行
 * @param {array} deps 依赖
 */
function useEffectOnce(fn, deps) {
  const isRunRef = useRef(false);

  useEffect(() => {
    if (isRunRef.current) {
      return;
    }

    isRunRef.current = fn();
  }, [deps]);
}

export default useEffectOnce;
